/*
 * @Author: wuhao930406 1148547900@qq.com
 * @Date: 2023-11-06 14:01:38
 * @LastEditors: wuhao930406 1148547900@qq.com
 * @LastEditTime: 2023-11-06 14:03:12
 * @FilePath: /wbn/src/components/CompanyName/components/txtviewer.jsx
 * @Description:
 *
 * Copyright (c) 2023 by ${git_name_email}, All Rights Reserved.
 */
import React, { useState, useEffect } from 'react';

function RemoteTxtFilePreview({url}) {
  const [fileContent, setFileContent] = useState('');
  const [error, setError] = useState(null);

  useEffect(() => {
    fetch(url)
      .then((response) => {
        return response?.text?.() ?? "无法加载...";
      })
      .then((data) => {
        setFileContent(data);
      })
      .catch((error) => {
        setError('资源无法加载...');
      });
  }, [url]);

  return (
    <div>
      {error ? (
        <div>{error}</div>
      ) : (
        <pre>{fileContent}</pre>
      )}
    </div>
  );
}

export default RemoteTxtFilePreview;
